package com.rhb.ca.web.struts.tag;

import java.text.*;
import org.apache.struts.taglib.*;
import javax.servlet.jsp.JspException;

public class TextTag extends org.apache.struts.taglib.html.TextTag{
	public TextTag() {
		super();
	}

	protected String formatStr = null;
	public String getFormat() {
		return (this.formatStr);
	}
	public void setFormat(String formatStr) {
		this.formatStr = formatStr;
	}

	protected String formatValue(Object value) throws JspException {
		if (value == null) {
			return "";
		}
		
		Format format = null;
		String outstr;
		if (value instanceof java.lang.String) {
			outstr = (String)value;
		}else if(formatStr==null){
			outstr = value.toString();
		}else if(value instanceof Number){
			format = new DecimalFormat(formatStr);
			outstr = format.format(value);
		}else if (value instanceof java.util.Date){
			format = new SimpleDateFormat(formatStr);
			outstr = format.format(value);
		}else outstr = value.toString();
		
		return TagUtils.getInstance().filter(outstr);
	}
	
	public void release(){
		super.release();
		formatStr = null;
	}
	
}
